package ca.bcit.comp_3512.assignment_02.business_logic;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import ca.bcit.comp_3512.assignment_02.data_managers.UserManager;
import ca.bcit.comp_3512.assignment_02.data_models.User;


@Named("newEmployee")
@RequestScoped
public class NewEmployee implements Serializable
{
    @Inject UserManager userManager;
    @Inject EditableUserList editableUserList;
    private String firstName;
    private String lastName;
    private String password;
    private boolean superUser;

    public NewEmployee() {}
    
    public String addEmployee()
    {
        User temp = new User();
        
        temp.setFirstName(firstName);
        temp.setLastName(lastName);
        temp.setPassword(password);
        temp.setSuperUser(superUser);
        
        userManager.persist(temp);
        editableUserList.refreshList();
        
        firstName = null;
        lastName = null;
        password = null;
        
        return "admin?faces-redirect=true";
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getPassword() {
        return password;
    }

    public boolean isSuperUser() {
        return superUser;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setSuperUser(boolean superUser) {
        this.superUser = superUser;
    }
}
